<template>
    <div class="template-form-Lu">
        <a-modal
            title="事项审批申请"
            :visible="applicationFormVisible"
            :maskClosable="false"
            :closable="true"
            :destroyOnClose="true"
            width="100%"
            :dialog-style="{ margin: '0 auto' }"
            wrapClassName="applicationModal-form-fullmodal-Lu"
            @cancel="closeVisible">
            <div class="applicationModal-div-box-Lu">
                <div class="tabs-card-edit-box">
                    <a-tabs type="card" v-model:activeKey="summaryActiveKey" @change="summaryActiveChange">
                        <a-tab-pane key="申请表" tab="申请表"></a-tab-pane>
                        <a-tab-pane key="流转记录" tab="流转记录"></a-tab-pane>
                    </a-tabs>
                </div>
                <div  class="tab-box-v1">
                    <div v-if="summaryActiveKey == '申请表'" style="width: 70%;margin: 0 auto;padding-top: 30px;padding-bottom: 30px;">
                        <a-spin :spinning="spinning">
                            <a-button class="blue-btn" @click="printClick('行政',formState,qmImgList)" v-if="linkName == '我的已办'">打印</a-button>
                            <a-form :form="form" ref="form" class="internalControl-reimbursement-model-form-box">
                                <a-descriptions bordered style="width: 100%;">
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='起草'|| linkName == '数据修订'">*</span>
                                            时&emsp;&emsp;间
                                        </span>
                                        <a-form-item ref="frq" prop="frq" class="zm-form-model">
                                            <a-date-picker
                                                v-if="linkName=='起草' || linkName == '数据修订'"
                                                style="width: 100%;min-width: 140px;"
                                                v-model="formState.frq"
                                                type="date"
                                                placeholder=""
                                                v-decorator="[
                                                    'frq', {initialValue:formState.frq,rules: rules.frq}]"
                                                />
                                                <span v-else>{{ moment(formState.frq).format('YYYY-MM-DD') }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            自然编号
                                        </span>
                                        <a-form-item ref="fzrbh" prop="fzrbh" class="zm-form-model">
                                            <a-input
                                                v-if="linkName=='起草' || linkName == '数据修订'"
                                                :disabled="true"
                                                v-model="formState.fzrbh"
                                                placeholder="自动生成，无需填写:"
                                                type="textarea"/>
                                            <span v-else>{{ formState.fzrbh }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='起草' || linkName == '数据修订'">*</span>
                                            类&emsp;&emsp;别
                                        </span>
                                        <a-form-item ref="flb" prop="flb" class="zm-form-model">
                                            <compSelector
                                                v-if="linkName=='起草' || linkName == '数据修订'"
                                                v-model="formState.flb"
                                                :defaultValue="formState.flb"
                                                :compType="typeSelect"
                                                @selectHandleChange="flbChange"
                                                placeholder="行政事务审批类别"
                                                dictionaryType="OA行政事务审批类别"
                                                class="oaApply-compSelector"
                                                style="width:200px !important;"
                                                v-decorator="[ 'flb', {initialValue:formState.flb,rules:rules.flb}]"/>
                                            <span v-else>{{ formState.flb?formState.flb.toString():'' }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='起草' || linkName == '数据修订'">*</span>
                                            事项名称
                                        </span>
                                        <a-form-item ref="fsx" prop="fsx" class="zm-form-model">
                                            <a-textarea
                                                v-if="linkName=='起草' || linkName == '数据修订'"
                                                v-model="formState.fsx"
                                                placeholder="请输入事项名称:"
                                                :auto-size="{ minRows: 2}"
                                                v-decorator="[
                                                    'fsx', {initialValue:formState.fsx,rules: rules.fsx}]"
                                            />
                                            <span v-else>{{ formState.fsx }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <!-- <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            合同审核单
                                            <a-button class="orange-btn" @click="selectContractClick" v-if="linkName == '起草' && !formState.fhtspmc">选择合同</a-button>
                                        </span>
                                        <a-form-item ref="fhtspmc" prop="fhtspmc" class="zm-form-model">
                                            <a-input
                                                v-if="linkName=='起草' || linkName == '数据修订'"
                                                :disabled="true"
                                                v-model="formState.fhtspmc"
                                                placeholder="点击勾选，无需填写:"
                                                style="width: 80%;"/>
                                            <span v-else>{{ formState.fhtspmc }}</span>
                                            <a-icon @click="delContractClick" v-if="formState.fhtspmc" type="delete" style="color: red;margin-left: 10px;font-size: 18px;"/>
                                        </a-form-item>
                                    </a-descriptions-item> -->
                                    <a-descriptions-item :span="3">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='起草' || linkName == '数据修订'">*</span>
                                            具体内容
                                        </span>
                                        <a-form-item ref="fnbyj" prop="fnbyj" class="zm-form-model">
                                            <a-textarea
                                                v-if="linkName=='起草' || linkName == '数据修订'"
                                                v-model="formState.fnbyj"
                                                placeholder="请输入具体内容:"
                                                :auto-size="{ minRows: 2}"
                                                v-decorator="[
                                                    'fnbyj', {initialValue:formState.fnbyj,rules: rules.fnbyj}]"
                                            />
                                            <span v-else>{{ formState.fnbyj }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3">
                                        <span slot="label" class="descriptions-label-slot">
                                            附&emsp;&emsp;件
                                        </span>
                                        <a-form-item ref="fnbyj" prop="fnbyj" class="zm-form-model">
                                            <uploadFilesList :config="uploadFilesListConfig" @emitFormid="emitFormid" :filesFormState="{...formState,frq:moment(formState.frq).format('YYYY-MM-DD')}"/>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('科室审核').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('科室审核').hjmc">*</span>
                                            主办科室意见
                                        </span>
                                        <a-form-item ref="fksldyj" prop="fksldyj" class="zm-form-model">
                                            <div style="width: 100%;" v-if="(descriptionsData('科室审核').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsReffksldyj"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('行政审批',formState.fksldyj,'fksldyj')"
                                                    v-decorator="[
                                                        'fksldyj', { initialValue:formState.fksldyj, rules: rules.fksldyj}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.fksldyjsj)"
                                                        :default-value="moment(formState.fksldyjsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'fksldyjsj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.fksldyj }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('科室审核')" :src="getUrl('科室审核')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.fksldyjr }}</span>
                                                    <span>{{ formState.fksldyjsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('中心分管领导审核').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('中心分管领导审核').hjmc">*</span>
                                            中心分管<br/>领导意见
                                        </span>
                                        <a-form-item ref="ffgldyj" prop="ffgldyj" class="zm-form-model">
                                            <div style="width: 100%;" v-if="(descriptionsData('中心分管领导审核').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsRefffgldyj"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('行政审批',formState.ffgldyj,'ffgldyj')"
                                                    v-decorator="[
                                                        'ffgldyj', { initialValue:formState.ffgldyj, rules: rules.ffgldyj}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.ffgldyjsj)"
                                                        :default-value="moment(formState.ffgldyjsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'ffgldyjsj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.ffgldyj }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('中心分管领导审核')" :src="getUrl('中心分管领导审核')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.ffgldyjr }}</span>
                                                    <span>{{ formState.ffgldyjsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('中心主要领导审核').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('中心主要领导审核').hjmc">*</span>
                                            中心主要<br/>领导批示
                                        </span>
                                        <a-form-item ref="fzxld" prop="fzxld" class="zm-form-model">
                                            <div style="width: 100%;" v-if="(descriptionsData('中心主要领导审核').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsReffzxld"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('行政审批',formState.fzxld,'fzxld')"
                                                    v-decorator="[
                                                        'fzxld', { initialValue:formState.fzxld, rules: rules.fzxld}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.fzxldpssj)"
                                                        :default-value="moment(formState.fzxldpssj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'fzxldpssj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.fzxld }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('中心主要领导审核')" :src="getUrl('中心主要领导审核')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.fzxldpsr }}</span>
                                                    <span>{{ formState.fzxldpssj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('中心主要领导审核').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            备注
                                        </span>
                                        <a-form-item ref="fnbyj" prop="fnbyj" class="zm-form-model">
                                            <a-input
                                                v-if="linkName == '中心主要领导审核' || linkName == '数据修订'"
                                                v-model="formState.fbz"
                                                placeholder="备注:"
                                                type="textarea"
                                            />
                                            <span v-else>{{ formState.fbz }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                </a-descriptions>
                            </a-form>
                        </a-spin>
                    </div>
                    <div v-if="summaryActiveKey == '流转记录'" style="padding-top: 30px;">
                        <transferRecords
                            ref="transferRecordsRef"
                            :config="circulationDataTableConfig"
                            @getCirculationQmImg="getCirculationQmImg"/>
                    </div>
                </div>
            </div>
            <template slot="footer">
                <div v-if="linkName == '科室审核'">
                    <a-button @click="closeVisible">关闭</a-button>
                    <a-button class="blue-btn" @click="onSubmit('提交')">中心分管领导审核</a-button>
                    <a-button class="blue-btn" @click="jobFg">中心分管领导审批</a-button>
                    <a-button class="blue-btn" @click="jobZyld">直达中心主要领导审批</a-button>
                    <a-button class="red-btn" @click="returnClick">退回</a-button>
                </div>
                <div v-else-if="linkName =='我的已办'">
                    <a-button @click="closeVisible" class="blue-btn">关闭</a-button>
                </div>
                <div v-else-if="linkName == '数据修订'">
                    <a-button class="blue-btn" @click="updataData">确认修订</a-button>
                </div>
                <div v-else>
                    <a-button key="back" @click="onSave('保存')">
                        保存
                    </a-button>
                    <a-button class="blue-btn" @click="onSubmit('提交')">
                        提交
                    </a-button>
                    <a-button v-if="linkName !== '起草'" @click="returnClick" class="red-btn">退回</a-button>
                </div>
            </template>
        </a-modal>
        <printModal ref="printModalRef" />
        <select-contract-modal ref="SelectContractModal" @getApplicantData="getApplicantData" />
    </div>
</template>
<script>
import compSelector from '@/components/compSelector/compSelector'
import {typeSelect,} from '@/components/compSearchCriteria/ContractType'
import {
    editFuntion,
    initBzFlow,
    saveFlow,
    submitFlow,
    queryJobByJobId,
    returnUpperzdyFlowJob,
    getMoreUserSignLinkList,
    pidgetlchj,
    selectSpd,
    deleteSpd,
} from './service/index'
import assessCheckApi from './service/api.js'
import transferRecords from '../modal/transferRecords'
import printModal from '../modal/printModal'
import uploadFilesList from '../modal/uploadFilesList'
import moment from 'moment'
import SelectContractModal from './selectContractModal.vue'
export default {
    components: {
        compSelector,
        transferRecords,
        printModal,
        SelectContractModal,
        uploadFilesList,
    },
    data() {
        return {
            typeSelect:typeSelect,
            moment:moment,
            applicationFormVisible: false,
            summaryActiveKey: '申请表',
            form:this.$form.createForm(this, { name: 'form' }),
            formState: {},
            circulationDataTableConfig: {
                api: assessCheckApi.flowJkPage,
                rowId: 'id',
                urlType: true,
                paramet:{
                    oaid: ''
                }
            },
            uploadFilesListConfig: {
                isUpload: false,
                isAttachmentView: true,
                fjAddApi: assessCheckApi.initBzFlow,
            },
            rules:{
                fzrbh: [{
                    required: true,
                    message: '请输入自然编号',
                    trigger: 'blur',
                }],
                frq: [{
                    type: 'object',
                    required: true,
                    message: '请选择日期',
                    trigger: 'blur',
                }],
                fsx: [{
                    required: true,
                    message: '请输入事项名称',
                    trigger: 'blur',
                }],
                fnbyj: [{
                    required: true,
                    message: '请输入具体内容',
                    trigger: 'blur',
                }],
                flb: [{
                    type: 'array',
                    required: true,
                    message: '请选择行政事务审批类别',
                    trigger: 'blur',
                }],
                fksldyj: [
                    { required: true, message: '请输入本科（室）意见', trigger: 'blur' }
                ],
                fbgsyj: [
                    { required: true, message: '请输入办公室意见', trigger: 'blur' }
                ],
                ffgldyj: [
                    { required: true, message: '请输入中心分管领导意见', trigger: 'blur' }
                ],
                fzxld: [
                    { required: true, message: '请输入中心主要领导意见', trigger: 'blur' }
                ],
            },
            filesListData: [],
            qmImgList: [],
            displayList: [],
            linkName: '起草',
            spinning: false,
        }
    },
    mounted() {
        this.uploadFilesListConfig.isUpload = (this.linkName == '起草' || this.linkName == '数据修订')?true:false
        this.uploadFilesListConfig.isAttachmentView = this.linkName == '起草'?true:false
    },
    methods: {
        getInitData(){
            this.formState = {}
        },
        getData(val){
            if(val){
                this.summaryActiveKey = '申请表'
                this.linkName = val.hjmc
                this.uploadFilesListConfig.isUpload = (this.linkName == '起草' || this.linkName == '数据修订')?true:false
                this.uploadFilesListConfig.isAttachmentView = this.linkName == '起草'?true:false
                this.formState = {}
                this.formState = {
                    ...val.oaMap,
                    jobid: val.jobMap?val.jobMap.id:''
                }
                this.formState.frq = val.oaMap.frq?moment(val.oaMap.frq):null
                this.formState.flb = val.oaMap.flb?val.oaMap.flb.split(','):null
                this.circulationDataTableConfig.paramet.oaid = this.formState.id
                this.qmImgList = []
                this.displayList = []
                this.getDisplayList()
            }
        },
        getDisplayList(){
            pidgetlchj({pid:this.formState.id}).then((res) => {
                let arr1 = res.result
                this.displayList = []
                this.displayList = res.result

                if(this.linkName == '数据修订'){
                    // this.displayList.splice(this.displayList.findIndex((item) => item.blzt == '待办'), 1);
                    const index = this.displayList.findIndex((item) => item.blzt == '待办');
                    if (index !== -1) {
                        this.displayList.splice(index, 1);
                    }
                    //console.log('this.displayList',this.displayList)
                }

                arr1.forEach(async item => {
                    if(item.blrid && item.blzt!=='待办'){
                        let resa = await getMoreUserSignLinkList({ids:item.blrid})
                        if(resa.success && resa.result.length){
                            if(resa.result[0].signLink == ''){
                                // //console.log('没有获得图片 signLink == 0')
                                this.qmImgList.push({
                                    hjmc: item.hjmc,
                                    url: null
                                })
                            } else {
                                this.qmImgList.push({
                                    hjmc: item.hjmc,
                                    url: resa.result[0].signLink+'&aa='+Date.now()
                                })
                                // //console.log('获得的签名图片列表',this.qmImgList)
                            }
                        } else {
                            // //console.log('没有获得图片')
                        }
                    } else {}
                })
                // //console.log('最终获得的签名图片列表---',this.qmImgList)
            })
        },
        closeVisible(){
            this.applicationFormVisible = false
            this.$emit('success')
        },
        summaryActiveChange(val){
            //console.log(val)
        },
        flbChange(val){
            //console.log(val)
            this.formState.flb = val
            this.form.setFieldsValue({
                flb: [val],
            });
        },
        getCirculationQmImg(item1,item2){
            //console.log('-----?????-----',item1,item2)
            this.qmImgList = []
            this.displayList = []
            this.qmImgList = item1
            this.displayList = [...item2]
            //console.log('111111111',this.qmImgList)
            //console.log('222222222',this.displayList)
        },
        getUrl(hjmcName){
            let url = ''
            // //console.log('没有？？？',this.qmImgList)
            this.qmImgList.forEach(item => {
                //console.log(hjmcName,item)
                if(item.hjmc == hjmcName){
                    url = item.url
                }
            })
            // //console.log(hjmcName,url)
            return url
        },
        descriptionsData(hjmc){
            let data = {}
            this.displayList.forEach((item,index) => {
                if(item.hjmc == hjmc){
                // //console.log('descriptionsData111',hjmc,item)
                    data = {...item}
                }
            })
            // //console.log('descriptionsData',data)
            return data
        },
        getInputOpinion(val,valueData){
            //console.log(val,valueData)
            let data = this.formState
            data[valueData.hjmc] = val
            this.form.setFieldsValue({
                fksldyj: this.formState.fksldyj,
                fbgsyj: this.formState.fbgsyj,
                ffgldyj: this.formState.ffgldyj,
                fzxld: this.formState.fzxld
            });
        },
        opinions(val1,val2,val3){
            // //console.log('=========',`reviewOpinionsRef${val3}`)
            //console.log(val1,val2,val3)
            // this.$refs[`reviewOpinionsRef${val3}`].getData({opinionType:val1,oldVal:val2,valueData:{hjmc:val3}})
            this.$refs[`reviewOpinionsRef${val3}`].getData({opinionType:val1,oldVal:val2,valueData:{hjmc:val3}})

        },
        emitFormid(val){
            this.formState = {
                jobid:val.jobMap.id,
                ...val.oaMap
            }
            //console.log('formState===',this.formState)
        },
        selectContractClick(){
            this.$refs.SelectContractModal.getData({})
        },
        delContractClick(){
            var that = this
            that.$confirm({
                title: '您确定要删除当前绑定的合同审核单吗?',
                onOk() {
                    let data = {
                        xzswid: that.formState.id,
                        htspid: that.formState.fhtsplcid
                    }
                    deleteSpd(data).then(res => {
                        if(res.success){
                            that.$message.success(res.message)
                            that.formState.fhtsplcid = ''
                            that.formState.fhtspmc = ''
                        } else {
                            that.$message.warning(res.message)
                        }
                    })
                },
                onCancel() {},
            });
        },
        async getApplicantData(val){
            //console.log(val)
            if(this.formState.id){
                this.formState.fhtsplcid = val.id
                this.formState.fhtspmc = val.name
                let htData = {
                    xzswid: this.formState.id,
                    htspid: this.formState.fhtsplcid
                }
                let res = await selectSpd(htData)
                if(res.code == 200){
                    this.$message.success(res.message)
                }
            } else {
                let data = {
                    frq: moment(this.formState.frq).format('YYYY-MM-DD'),
                    fhtsplcid: val.id,
                    fhtspmc: val.name,
                    id: ''
                }
                let res = await initBzFlow(data)
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.formState = {
                        ...res.result.oaMap,
                        jobid: res.result.jobMap.id
                    }
                    this.formState.frq = this.formState.frq?moment(this.formState.frq):null

                    let htData = {
                        xzswid: this.formState.id,
                        htspid: this.formState.fhtsplcid
                    }
                    selectSpd(htData)
                }
            }
        },
        onSave(){
            //console.log('保存',this.linkName)
            let data = {}
            let sdata = {
                jobid: this.formState.jobid,
                oaid: this.formState.id,
                map: {},
                opinion: '',
            }
            if(this.linkName == '起草'){
                data = {
                    frq: moment(this.formState.frq).format('YYYY-MM-DD'),
                    // fzrbh: this.formState.fzrbh,
                    fsx: this.formState.fsx,
                    fnbyj: this.formState.fnbyj,
                    flb: this.formState.flb?this.formState.flb.toString():'',
                    id: this.formState.id?this.formState.id:''
                }
                sdata.map = {
                    ...data
                }
                this.formState.id?this.saveFlowFuntion(sdata):this.initBzFlowFuntion(data)
            } else if(this.linkName == '科室审核'){
                sdata.map = {
                    fksldyj: this.formState.fksldyj,
                    fksldyjr: this.formState.fksldyjr,
                    fksldyjsj: this.formState.fksldyjsj
                }
                sdata.opinion = this.formState.fksldyj,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '办公室意见'){
                sdata.map = {
                    fbgsyj: this.formState.fbgsyj,
                    fbgsyjr: this.formState.fbgsyjr,
                    fbgsyjsj: this.formState.fbgsyjsj
                }
                sdata.opinion = this.formState.fbgsyj,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '中心分管领导审核'){
                sdata.map = {
                    ffgldyj: this.formState.ffgldyj,
                    ffgldyjr: this.formState.ffgldyjr,
                    ffgldyjsj: this.formState.ffgldyjsj
                }
                sdata.opinion = this.formState.ffgldyj,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '中心主要领导审核'){
                sdata.map = {
                    fzxld: this.formState.fzxld,
                    fzxldpsr: this.formState.fzxldpsr,
                    fzxldpssj: this.formState.fzxldpssj,
                    fbz: this.formState.fbz,
                }
                sdata.opinion = this.formState.fzxld,
                this.saveFlowFuntion(sdata)
            }
        },
        onSubmit(){
            this.form.validateFields((err, values) => {
                if (!err) {
                    var that = this
                    that.$confirm({
                        title: '您确定要提交吗?',
                        onOk() {
                            that.spinning = true
                            let data = {
                                jobid: that.formState.jobid,
                                oaid: that.formState.id,
                                map: {},
                                opinion: '',
                            }
                            if(that.linkName == '起草'){
                                data.map = {
                                    frq: moment(that.formState.frq).format('YYYY-MM-DD'),
                                    // fzrbh: that.formState.fzrbh,
                                    fsx: that.formState.fsx,
                                    fnbyj: that.formState.fnbyj,
                                    flb: that.formState.flb?that.formState.flb.toString():'',
                                    id: that.formState.id?that.formState.id:'',
                                    fsffqlc: that.formState.id?'':'是',
                                }
                                that.formState.id?that.submitFlowFuntion(data):that.initBzFlowFuntion(data.map,'1')
                            } else if(that.linkName == '科室审核'){
                                data.map = {
                                    fksldyj: that.formState.fksldyj,
                                    fksldyjr: that.formState.fksldyjr,
                                    fksldyjsj: that.formState.fksldyjsj
                                }
                                data.opinion = that.formState.fksldyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '办公室意见'){
                                data.map = {
                                    fbgsyj: that.formState.fbgsyj,
                                    fbgsyjr: that.formState.fbgsyjr,
                                    fbgsyjsj: that.formState.fbgsyjsj
                                }
                                sdata.opinion = that.formState.fbgsyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '中心分管领导审核'){
                                data.map = {
                                    ffgldyj: that.formState.ffgldyj,
                                    ffgldyjr: that.formState.ffgldyjr,
                                    ffgldyjsj: that.formState.ffgldyjsj
                                }
                                data.opinion = that.formState.ffgldyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '中心主要领导审核'){
                                data.map = {
                                    fzxld: that.formState.fzxld,
                                    fzxldpsr: that.formState.fzxldpsr,
                                    fzxldpssj: that.formState.fzxldpssj,
                                    fbz: that.formState.fbz,
                                }
                                data.opinion = that.formState.fzxld,
                                that.submitFlowFuntion(data)
                            }
                        },
                        onCancel() {},
                    });
                }
            })
        },
        initBzFlowFuntion(data,type){
            initBzFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.formState = {}
                    this.formState = {
                        ...res.result.oaMap,
                        jobid: res.result.jobMap.id
                    }
                    this.formState.frq = moment(this.formState.frq)
                    if(type){
                        this.closeVisible()
                    }
                } else {
                    this.$message.warning(res.message)
                }
            })
        },
        saveFlowFuntion(data){
            this.spinning = true
            saveFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                } else {
                    this.$message.warning(res.message)
                }
                this.spinning = false
            })
        },
        submitFlowFuntion(data){
            submitFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.warning(res.message)
                }
                this.spinning = false
            })
        },
        // 退回
        returnClick(){
            this.form.validateFields((err, values) => {
                if (!err) {
                    var that = this
                    that.$confirm({
                        title: '您确定要退回吗?',
                        onOk() {
                            that.spinning = true
                            queryJobByJobId({jobid:that.formState.jobid}).then(res => {
                                let list = res.result.jobHistoryList
                                let slist = list.filter(item => item.fhjmc == '起草')
                                const sortedDates = slist.sort((a, b) => new Date(b) - new Date(a));
                                that.returnFuntion(that.formState.jobid,sortedDates[slist.length - 1].id)
                            })
                        },
                        onCancel() {},
                    });
                }
            })
        },
        returnFuntion(jobid,ids){
            let returnStr = ''
            if(this.linkName == '科室审核'){
                returnStr = this.formState.fksldyj
            } else if(this.linkName == '办公室意见'){
                returnStr = this.formState.fbgsyj
            } else if(this.linkName == '中心分管领导审核'){
                returnStr = this.formState.ffgldyj
            } else if(this.linkName == '中心主要领导审核'){
                returnStr = this.formState.fzxld
            }
            let data = {
                jobid: jobid,
                opinion: returnStr,
                shjid: ids,
                lcmbbm: '',
                smgflag: '',
                smsContent: '',
            }
            returnUpperzdyFlowJob(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.error(res.message)
                }
                this.spinning = false
            })
        },
        jobFg(){
            this.form.validateFields((err, values) => {
                if (!err) {
                    var that = this
                    that.$confirm({
                        title: '您确定要提交至中心分管领导审批吗?',
                        onOk() {
                            let data = {
                                jobid: that.formState.jobid,
                                oaid: that.formState.id,
                                map: {
                                    fksldyj: that.formState.fksldyj,
                                    fksldyjr: that.formState.fksldyjr,
                                    fksldyjsj: that.formState.fksldyjsj,
                                    fsftgdwld: '是',
                                },
                                opinion: that.formState.fksldyj,
                            }

                            submitFlow(data).then(res => {
                                if(res.code == 200){
                                    that.$message.success(res.message)
                                    that.closeVisible()
                                } else {
                                    that.$message.warning(res.message)
                                }
                            })
                        },
                        onCancel() {},
                    });
                }
            })
        },
        jobZyld(){
            this.form.validateFields((err, values) => {
                if (!err) {
                    var that = this
                    that.$confirm({
                        title: '您确定要跳过中心分管领导审批，提交至中心主要领导审批吗?',
                        onOk() {
                            let data = {
                                jobid: that.formState.jobid,
                                oaid: that.formState.id,
                                map: {
                                    fksldyj: that.formState.fksldyj,
                                    fksldyjr: that.formState.fksldyjr,
                                    fksldyjsj: that.formState.fksldyjsj
                                },
                                opinion: that.formState.fksldyj,
                                nextNode: '中心主要领导审核',
                            }

                            submitFlow(data).then(res => {
                                if(res.code == 200){
                                    that.$message.success(res.message)
                                    that.closeVisible()
                                } else {
                                    that.$message.warning(res.message)
                                }
                            })
                        },
                        onCancel() {},
                    });
                }
            })
        },
        printClick(type,value,qmValue){
            this.$refs.printModalRef.modalClick(type,value,qmValue)
        },
        yjTimeChange(val,name){
            let data = this.formState
            data[name] = moment(val).format('YYYY-MM-DD HH:mm:ss')
        },
        updataData(){
            var that = this
            that.$confirm({
                title: '您确定修改当前表单数据吗?',
                onOk() {
                    let data = {
                        id: that.formState.id,
                        frq: moment(that.formState.frq).format('YYYY-MM-DD'),
                        // fzrbh: that.formState.fzrbh,
                        fsx: that.formState.fsx,
                        fnbyj: that.formState.fnbyj,
                        flb: that.formState.flb?that.formState.flb.toString():'',
                        fksldyj: that.formState.fksldyj,
                        fksldyjr: that.formState.fksldyjr,
                        fksldyjsj: that.formState.fksldyjsj,
                        // fbgsyj: that.formState.fbgsyj,
                        // fbgsyjr: that.formState.fbgsyjr,
                        // fbgsyjsj: that.formState.fbgsyjsj,
                        ffgldyj: that.formState.ffgldyj,
                        ffgldyjr: that.formState.ffgldyjr,
                        ffgldyjsj: that.formState.ffgldyjsj,
                        fzxld: that.formState.fzxld,
                        fzxldpsr: that.formState.fzxldpsr,
                        fzxldpssj: that.formState.fzxldpssj,
                    }
                    //console.log(data)
                    that.spinning = true
                    editFuntion(data).then(res => {
                        if(res.code == 200){
                            that.$message.success(res.message)
                        } else {
                            that.$message.warning(res.message)
                        }
                        that.spinning = false
                    })
                },
                onCancel() {
                    //console.log('Cancel');
                },
            });
        },
    }
}
</script>
<style>
@import url('../css/oaLess.css');
</style>
